package com.lzm.ydpt.module.mall.activity;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.baseadapter.rv.RvCommonAdapter;
import com.byt.framlib.baseadapter.rv.RvViewHolder;
import com.byt.framlib.commonutils.image.ImageLoaderUtils;
import com.byt.framlib.commonwidget.LoadingTip;
import com.byt.framlib.commonwidget.NormalTitleBar;
import com.byt.framlib.commonwidget.OnNoDoubleClickListener;
import com.byt.framlib.commonwidget.refresh.RefreshHeaderView;
import com.lzm.ydpt.R;
import com.lzm.ydpt.entity.mall.ShopInfoBean;
import com.lzm.ydpt.mvp.contract.MallFollowContract;
import com.lzm.ydpt.mvp.presenterimpl.MallFollowPresenterImpl;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 关注商家
 */
public class MallFollowActivity extends BaseActivity<MallFollowPresenterImpl> implements MallFollowContract.View {

    @BindView(R.id.ntb_mall_follow)
    NormalTitleBar ntb_mall_follow;
    @BindView(R.id.ltp_mall_follow)
    LoadingTip ltp_mall_follow;
    @BindView(R.id.srf_mall_follow)
    SmartRefreshLayout srf_mall_follow;
    @BindView(R.id.rv_mall_follow)
    RecyclerView rv_mall_follow;
    private RvCommonAdapter<ShopInfoBean> commonAdapter = null;
    private List<ShopInfoBean> shopInfoBeans = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.activity_mall_follow;
    }

    @Override
    public MallFollowPresenterImpl initPreData() {
        return new MallFollowPresenterImpl(this);
    }

    @Override
    public void initView() {
        setNtbTitle(ntb_mall_follow, false);
        ntb_mall_follow.setTitleText("关注商户");
        ntb_mall_follow.setOnBackListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        initRefrsh();
        initAdapter();

    }

    private void initRefrsh() {
        setRefreshLayout(srf_mall_follow);
        srf_mall_follow.setEnableRefresh(true);
        srf_mall_follow.setEnableLoadMore(false);
        srf_mall_follow.setRefreshHeader(new RefreshHeaderView(mBContext).getHeaderStyleStaffF4());
        srf_mall_follow.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {

            }
        });
    }

    private void initAdapter() {
        rv_mall_follow.setLayoutManager(new LinearLayoutManager(mBContext));
        commonAdapter = new RvCommonAdapter<ShopInfoBean>(mBContext, shopInfoBeans, R.layout.item_follow_shop_rv) {
            @Override
            protected void convert(RvViewHolder holder, ShopInfoBean shopInfoBean, int position) {
                ImageLoaderUtils.displayCircle(holder.getView(R.id.img_follow_shop), shopInfoBean.getImage_src());
                holder.setText(R.id.tv_shop_name_follow, shopInfoBean.getStore_name());
                holder.setText(R.id.tv_shop_follower_num, "18w+" + "粉丝");
                holder.setOnClickListener(R.id.tv_follow_shop_state, new OnNoDoubleClickListener() {
                    @Override
                    protected void onNoDoubleClick(View v) {
                        showShortToast("已关注");
                    }
                });
            }
        };
        rv_mall_follow.setAdapter(commonAdapter);
    }

    @Override
    public void onMallFollow() {

    }

    @Override
    public void showMessage(String message, String method) {

    }

    @Override
    public void showErrorView(String msg) {

    }
}
